package com.purong.purong.fragment;

import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.purong.purong.Contant;
import com.purong.purong.R;
import com.purong.purong.activity.BankLoanDetialActivity;
import com.purong.purong.activity.HouseLoanActivity;
import com.purong.purong.activity.IntentionActivity;
import com.purong.purong.activity.LoanSearchActivity;
import com.purong.purong.adapter.BankLoanAdapter;
import com.purong.purong.bean.CreditSearchBean;
import com.purong.purong.bean.CreditSearchBean.SearchType;
import com.purong.purong.bean.CreditSearchBean.SearchType.SearchItem;
import com.purong.purong.bean.BankLoanBean;
import com.purong.purong.bean.BankLoanSearchListBean;
import com.purong.purong.bean.SearchValueBean;
import com.purong.purong.util.CommonUtil;
import com.purong.purong.util.SharePreUtil;
import com.purong.purong.widget.SearchNormalDialog;
import com.purong.purong.widget.SearchMoreDialog;
import com.purong.purong.widget.LoadingView;
import com.yao.sdk.net.ResponseInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import in.srain.cube.views.ptr.PtrCustomHandler;
import in.srain.cube.views.ptr.PtrDefaultCustomHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrPuRongLayout;

/**
 * Created by wenjiezeng on 2017/10/27.
 */
public class BankLoanFragment extends BaseFragment  {
    private View headView,footView;
    private ImageView intentionImg;
    private LinearLayout footBottom;
    private SearchNormalDialog pledgeSearchDialog, orderSearchDialog;
    private SearchMoreDialog moreSearchDialog;
    private PtrPuRongLayout mPtrFrame;
    private BankLoanAdapter mAdapter;
    private ListView mListView;
    private LinearLayout topTitleBar;
    private View cutLine;
    private int topHeight;
    private List<BankLoanBean> loanList = new ArrayList<>();
    private LoadingView loadView;
    private SearchValueBean pledgeValue, orderValue;
    private ArrayList<SearchValueBean> mPledgeList;
    private ArrayList<SearchValueBean> mOrderList;
    private ArrayList<SearchItem> mMoreList;
    private CreditSearchBean searchBean;
    private TextView pledgeTvOne, orderTvOne, moreTvOne, pledgeTvTwo, orderTvTwo, moreTvTwo;
    private ImageView pledgeImgOne, orderImgOne, moreImgOne, pledgeImgTwo, orderImgTwo, moreImgTwo;
    private int page = 1;
    private Map<String,String> itemMap=new HashMap<>();
    @Override
    public void initView(View rootView) {
        mListView = (ListView) rootView.findViewById(R.id.list_view);
        pledgeTvTwo = (TextView) rootView.findViewById(R.id.pledge_tv_two);
        orderTvTwo = (TextView) rootView.findViewById(R.id.order_tv_two);
        moreTvTwo = (TextView) rootView.findViewById(R.id.more_tv_two);
        pledgeImgTwo = (ImageView) rootView.findViewById(R.id.pledge_img_two);
        orderImgTwo = (ImageView) rootView.findViewById(R.id.order_img_two);
        moreImgTwo = (ImageView) rootView.findViewById(R.id.more_img_two);

        headView = getActivity().getLayoutInflater().inflate(R.layout.bank_loan_head_view, null);
        initCatClick(headView);
        intentionImg=(ImageView) headView.findViewById(R.id.intention_img);
        int imgWidth=CommonUtil.getScreenWidth(getActivity());
        int imgHeight=(int)(imgWidth/5.85);
        intentionImg.setLayoutParams(new LinearLayout.LayoutParams(imgWidth,imgHeight));
        intentionImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), IntentionActivity.class);
                startActivity(intent);
            }
        });
        topHeight = CommonUtil.dip2px(getActivity(), 186+10+14)+imgHeight;
        footView=getActivity().getLayoutInflater().inflate(R.layout.bank_loan_foot_view, null);
        footBottom=(LinearLayout) footView.findViewById(R.id.foot_bottom);

        pledgeTvOne = (TextView) headView.findViewById(R.id.pledge_tv_one);
        orderTvOne = (TextView) headView.findViewById(R.id.order_tv_one);
        moreTvOne = (TextView) headView.findViewById(R.id.more_tv_one);
        pledgeImgOne = (ImageView) headView.findViewById(R.id.pledge_img_one);
        orderImgOne = (ImageView) headView.findViewById(R.id.order_img_one);
        moreImgOne = (ImageView) headView.findViewById(R.id.more_img_one);
        loadView = (LoadingView) headView.findViewById(R.id.loading_view);
        loadView.setNoResultToast("未找到符合条件的产品","清空筛选");
        loadView.setLoadListener(new LoadingView.OnLoadListener() {
            @Override
            public void onReload() {
                getLoan(true);
            }

            @Override
            public void onRefresh() {
                if (mPledgeList != null) {
                    for (int i = 0; i < mPledgeList.size(); i++) {
                        if (mPledgeList.get(i).getItem().equals("-1")) {
                            mPledgeList.get(i).setCheck(true);
                            pledgeValue = mPledgeList.get(i);
                        } else {
                            mPledgeList.get(i).setCheck(false);
                        }
                    }
                }
                if (mOrderList != null) {
                    for (int i = 0; i < mOrderList.size(); i++) {
                        if (mOrderList.get(i).getItem().equals("-1")) {
                            mOrderList.get(i).setCheck(true);
                            orderValue = mOrderList.get(i);
                        } else {
                            mOrderList.get(i).setCheck(false);
                        }
                    }
                }
                if (mMoreList != null) {
                    for (int i = 0; i < mMoreList.size(); i++) {
                        for (int j = 0; j < mMoreList.get(i).getValue().size(); j++) {
                            mMoreList.get(i).getValue().get(j).setCheck(false);
                        }
                    }
                }

                pledgeTvOne.setText("不限抵押");
                pledgeTvTwo.setText("不限抵押");
                orderTvOne.setText("默认排序");
                orderTvTwo.setText("默认排序");
                setStatus(pledgeTvOne, pledgeTvTwo, pledgeImgOne, pledgeImgTwo, 1);
                setStatus(orderTvOne, orderTvTwo, orderImgOne, orderImgTwo, 1);
                setStatus(moreTvOne, moreTvTwo, moreImgOne, moreImgTwo, 1);
                getLoan(true);
            }
        });

        topTitleBar = (LinearLayout) rootView.findViewById(R.id.top_title_bar);
        cutLine=(View) rootView.findViewById(R.id.cut_line);
        mAdapter = new BankLoanAdapter(getActivity(), loanList);

        mListView.addHeaderView(headView);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position!=0&&(position<=loanList.size())){
                    Intent intent=new Intent(getActivity(),BankLoanDetialActivity.class);
                    intent.putExtra("LOAN",loanList.get(position-1));
                    startActivity(intent);
                }
            }
        });

        mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                int top = headView.getTop();
                int h = Math.abs(top);
                if (h <= topHeight) {
                    topTitleBar.setVisibility(View.GONE);
                    cutLine.setVisibility(View.GONE);
                }
                if (h > topHeight) {
                    topTitleBar.setVisibility(View.VISIBLE);
                    cutLine.setVisibility(View.VISIBLE);

                }
            }
        });

        mPtrFrame = (PtrPuRongLayout) rootView.findViewById(R.id.rotate_header_list_view_frame);
        mPtrFrame.setPtrHandler(new PtrCustomHandler() {
            @Override
            public boolean checkCanDoLoadMore(PtrFrameLayout frame, View content, View footer) {
                if (loanList.size() == 0) {
                    return false;
                } else {
                    return PtrDefaultCustomHandler.checkContentCanBePulledUp(frame, content, footer);
                }

            }

            @Override
            public void onLoadMoreBegin(PtrFrameLayout frame) {
                getLoan(false);

            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                getLoan(true);
            }

            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultCustomHandler.checkContentCanBePulledDown(frame, content, header);
//                return (isRequesting||loanList.size()>0)?false:true;
            }
        });

        rootView.findViewById(R.id.pledge_lay_two).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pledgeSearchDialog == null) {
                    if (mPledgeList == null) {
                        getSearch("2", "1");
                    } else {
                        initPledgeDialog();
                        pledgeSearchDialog.show();
                    }
                } else {
                    pledgeSearchDialog.show();
                }
            }
        });
        rootView.findViewById(R.id.order_lay_two).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (orderSearchDialog == null) {
                    if (mOrderList == null) {
                        getSearch("2", "2");
                    } else {
                        initOrderDialog();
                    }
                } else {
                    orderSearchDialog.show();
                }
            }
        });
        rootView.findViewById(R.id.more_lay_two).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (moreSearchDialog == null) {
                    if (mMoreList == null) {
                        getSearch("2", "3");
                    } else {
                        initMoreDialog();
                    }
                } else {
                    moreSearchDialog.show();
                }
            }
        });
        headView.findViewById(R.id.pledge_lay_one).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pledgeSearchDialog == null) {
                    if (mPledgeList == null) {
                        getSearch("2", "1");
                    } else {
                        initPledgeDialog();
                        pledgeSearchDialog.show();
                    }
                } else {
                    pledgeSearchDialog.show();
                }
            }
        });
        headView.findViewById(R.id.order_lay_one).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (orderSearchDialog == null) {
                    if (mOrderList == null) {
                        getSearch("2", "2");
                    } else {
                        initOrderDialog();
                        orderSearchDialog.show();
                    }
                } else {
                    orderSearchDialog.show();
                }
            }
        });
        headView.findViewById(R.id.more_lay_one).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (moreSearchDialog == null) {
                    if (mMoreList == null) {
                        getSearch("2", "3");
                    } else {
                        initMoreDialog();
                    }
                } else {
                    moreSearchDialog.show();
                }
            }
        });

    }

    private void setStatus(TextView tv, TextView tv2, ImageView iv, ImageView iv2, int status) {
        //status 1:下黑，2：下蓝，3：上黑，4：上篮
        switch (status) {
            case 1:
                tv.setTextColor(getResources().getColor(R.color.text_gray));
                iv.setImageResource(R.drawable.cart_gray_down);
                tv2.setTextColor(getResources().getColor(R.color.text_gray));
                iv2.setImageResource(R.drawable.cart_gray_down);
                break;
            case 2:
                tv.setTextColor(getResources().getColor(R.color.blue));
                iv.setImageResource(R.drawable.cart_blue_down);
                tv2.setTextColor(getResources().getColor(R.color.blue));
                iv2.setImageResource(R.drawable.cart_blue_down);
                break;
//            case 3:
//                tv.setTextColor(getResources().getColor(R.color.text_gray));
//                iv.setImageResource(R.drawable.cart_gray_up);
//                tv2.setTextColor(getResources().getColor(R.color.text_gray));
//                iv2.setImageResource(R.drawable.cart_gray_up);
//                break;
            case 4:
                tv.setTextColor(getResources().getColor(R.color.blue));
                iv.setImageResource(R.drawable.cart_blue_top);
                tv2.setTextColor(getResources().getColor(R.color.blue));
                iv2.setImageResource(R.drawable.cart_blue_top);
                break;
        }
    }
    private void initCatClick(View headView){
        headView.findViewById(R.id.sbz).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<SearchValueBean> list=new ArrayList<SearchValueBean>();
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("1");
                bean.setParentFiled("loan_identity");
                list.add(bean);
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_MORE",list);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.gth).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<SearchValueBean> list=new ArrayList<SearchValueBean>();
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("2");
                bean.setParentFiled("loan_identity");
                list.add(bean);
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_MORE",list);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.qyz).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<SearchValueBean> list=new ArrayList<SearchValueBean>();
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("3");
                bean.setParentFiled("loan_identity");
                list.add(bean);
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_MORE",list);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.zyzy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<SearchValueBean> list=new ArrayList<SearchValueBean>();
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("5");
                bean.setParentFiled("loan_identity");
                list.add(bean);
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_MORE",list);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.xyd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("4");
                bean.setParentFiled("loan_pledge");
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_PLEDGE",bean);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.dyd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("1");
                bean.setParentFiled("loan_pledge");
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_PLEDGE",bean);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.cd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchValueBean bean=new SearchValueBean();
                bean.setItem("2");
                bean.setParentFiled("loan_pledge");
                Intent intent=new Intent(getActivity(), LoanSearchActivity.class);
                intent.putExtra("CHOSE_PLEDGE",bean);
                startActivity(intent);
            }
        });
        headView.findViewById(R.id.fd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), HouseLoanActivity.class);
                startActivity(intent);
            }
        });
    }
    private void initOrderDialog() {
        orderSearchDialog = new SearchNormalDialog(getActivity(), mOrderList, false,true, new SearchNormalDialog.OnSearchChoseListener() {
            @Override
            public void onChose(int position) {
                orderValue = mOrderList.get(position);
                getLoan(true);
            }

            @Override
            public void onShow() {
                int height;
                if (loanList.size()==0){
                    height =CommonUtil.getScreenHeight(getActivity())-CommonUtil.getStatusBarHeight(getActivity())-CommonUtil.dip2px(getActivity(),45+50+50)-loadView.getHeight();
                }else {
                    height =CommonUtil.getScreenHeight(getActivity())-CommonUtil.getStatusBarHeight(getActivity())-CommonUtil.dip2px(getActivity(),45+50+50)- loanList.size()*CommonUtil.dip2px(getActivity(),100);
                }
                footBottom.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height));
                mListView.addFooterView(footView);
                if (topTitleBar.getVisibility()==View.GONE)
                mListView.setSelectionFromTop(1,CommonUtil.dip2px(getActivity(),50));
                setStatus(orderTvOne, orderTvTwo, orderImgOne, orderImgTwo, 4);
            }

            @Override
            public void onDismiss() {
                mListView.removeFooterView(footView);
                if (orderValue != null) {
                    orderTvOne.setText(orderValue.getTitle());
                    orderTvTwo.setText(orderValue.getTitle());
                    if (orderValue.getItem().equals("-1")) {
                        setStatus(orderTvOne, orderTvTwo, orderImgOne, orderImgTwo, 1);
                    } else {
                        setStatus(orderTvOne, orderTvTwo, orderImgOne, orderImgTwo, 2);
                    }

                } else {
                    setStatus(orderTvOne, orderTvTwo, orderImgOne, orderImgTwo, 1);
                }
            }
        });

    }

    private void initMoreDialog() {
        moreSearchDialog = new SearchMoreDialog(getActivity(), mMoreList, true,new SearchMoreDialog.OnSearchChoseListener() {
            @Override
            public void onConfirm() {
                getLoan(true);
            }

            @Override
            public void onShow() {
                int height;
                if (loanList.size()==0){
                    height =CommonUtil.getScreenHeight(getActivity())-CommonUtil.getStatusBarHeight(getActivity())-CommonUtil.dip2px(getActivity(),45+50+50)-loadView.getHeight();
                }else {
                    height =CommonUtil.getScreenHeight(getActivity())-CommonUtil.getStatusBarHeight(getActivity())-CommonUtil.dip2px(getActivity(),45+50+50)- loanList.size()*CommonUtil.dip2px(getActivity(),100);
                }
                footBottom.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height));
                mListView.addFooterView(footView);
                if (topTitleBar.getVisibility()==View.GONE)
                mListView.setSelectionFromTop(1,CommonUtil.dip2px(getActivity(),50));
                setStatus(moreTvOne, moreTvTwo, moreImgOne, moreImgTwo, 4);
            }

            @Override
            public void onDismiss() {
                mListView.removeFooterView(footView);
                boolean hasCheck = false;
                for (int i = 0; i < mMoreList.size(); i++) {
                    for (int j = 0; j < mMoreList.get(i).getValue().size(); j++) {
                        if (mMoreList.get(i).getValue().get(j).isCheck()) {
                            hasCheck = true;
                            break;
                        }
                    }
                }
                if (hasCheck) {
                    setStatus(moreTvOne, moreTvTwo, moreImgOne, moreImgTwo, 2);
                } else {
                    setStatus(moreTvOne, moreTvTwo, moreImgOne, moreImgTwo, 1);
                }
            }
        });
        moreSearchDialog.show();
    }

    private void initPledgeDialog() {
        pledgeSearchDialog = new SearchNormalDialog(getActivity(), mPledgeList, true,true, new SearchNormalDialog.OnSearchChoseListener() {
            @Override
            public void onChose(int position) {
                pledgeValue = mPledgeList.get(position);
                getLoan(true);
            }

            @Override
            public void onShow() {
                int height;
                if (loanList.size()==0){
                    height =CommonUtil.getScreenHeight(getActivity())-CommonUtil.getStatusBarHeight(getActivity())-CommonUtil.dip2px(getActivity(),45+50+50)-loadView.getHeight();
                }else {
                    height =CommonUtil.getScreenHeight(getActivity())-CommonUtil.dip2px(getActivity(),45+50+50)- loanList.size()*CommonUtil.dip2px(getActivity(),100);
                }
                footBottom.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height));
                mListView.addFooterView(footView);
                if (topTitleBar.getVisibility()==View.GONE)
                mListView.setSelectionFromTop(1,CommonUtil.dip2px(getActivity(),50));
                setStatus(pledgeTvOne, pledgeTvTwo, pledgeImgOne, pledgeImgTwo, 4);
            }

            @Override
            public void onDismiss() {
                mListView.removeFooterView(footView);
                if (pledgeValue != null) {
                    pledgeTvOne.setText(pledgeValue.getTitle());
                    pledgeTvTwo.setText(pledgeValue.getTitle());
                    if (pledgeValue.getItem().equals("-1")) {
                        setStatus(pledgeTvOne, pledgeTvTwo, pledgeImgOne, pledgeImgTwo, 1);
                    } else {
                        setStatus(pledgeTvOne, pledgeTvTwo, pledgeImgOne, pledgeImgTwo, 2);
                    }

                } else {
                    setStatus(pledgeTvOne, pledgeTvTwo, pledgeImgOne, pledgeImgTwo, 1);
                }

            }
        });
    }

    private void getSearch(String needShow, String type) {
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("need_show", needShow);
        params.put("type", type);
        if (needShow.equals("1")) {
            request(Contant.LOAN_SEARCH, params, true, false);
        } else {
            request(Contant.LOAN_SEARCH, params, true, true);
        }

    }


    @Override
    public void initData() {
        getSearch("1", "1");
        getLoan(true);
    }


    private void getLoan(boolean clear) {
        cancelRequest();
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("province_id", SharePreUtil.getInstance(getActivity()).getLoactionParentId());
        params.put("city_id",SharePreUtil.getInstance(getActivity()).getLoactionAreaId());
        if (searchBean!=null&&searchBean.getLoan_loan_item_list()!=null){
            itemMap.clear();
            List<SearchType> typeList=searchBean.getLoan_loan_item_list();
            for (int i = 0; i <typeList.size() ; i++) {
                for (int j = 0; j <typeList.get(i).getSearch_item().size() ; j++) {
                    for (int k = 0; k <typeList.get(i).getSearch_item().get(j).getValue().size() ; k++) {
                        if (typeList.get(i).getSearch_item().get(j).getValue().get(k).isCheck()){
                            itemMap.put(typeList.get(i).getSearch_item().get(j).getFiled(),typeList.get(i).getSearch_item().get(j).getValue().get(k).getItem());
                        }
                    }
                }
            }
            for (Map.Entry<String, String> entry : itemMap.entrySet()) {
                params.put(entry.getKey(),entry.getValue());
            }
        }
        if (clear) {
            page =1;
            if (loanList.size()==0){
                loadView.loading();
            }
//            loanList.clear();
//            mAdapter.notifyDataSetChanged();
//            loadView.loading();

        }
//        noResult.setVisibility(View.GONE);
        params.put("page", page + "");

        if (!request(Contant.LOAN_SEARCH_LIST, params, true)) {
            if (clear&&loanList.size()==0)
                loadView.fail();
            if (!hasDestroy())
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        if (mPtrFrame.isRefreshing()) {
                            mPtrFrame.refreshComplete();
                        }
                    }
                }, 100);
        }
    }

    @Override
    public int getRootViewId() {
        return R.layout.fragment_bank_loan;
    }

    @Override
    public void onResponse(ResponseInfo responseInfo) {
        if (hasDestroy())
            return;
        super.onResponse(responseInfo);
        if (responseInfo.url.equals(Contant.LOAN_SEARCH_LIST)) {
            if (mPtrFrame.isRefreshing()) {
                mPtrFrame.refreshComplete();
            }
            if (responseInfo.isRequestOk) {
                try {
                    BankLoanSearchListBean bean=JSON.parseObject(responseInfo.content,BankLoanSearchListBean.class);
                    if (responseInfo.params.get("page").equals("1"))
                        loanList.clear();
                    if (bean!=null&&bean.getLoan_search_list()!=null){
                        if (bean.getLoan_search_list().size()>0)
                            page++;
                        loanList.addAll(bean.getLoan_search_list());
                        mAdapter.notifyDataSetChanged();

                    }
                    if (loanList.size()==0){
                        if (itemMap.size()==0){
                            loadView.noResult();
                        }else {
                            loadView.noResultWithRefresh();
                        }

                    }else {
                        loadView.finish();
                    }


                } catch (Exception e) {

                    if (page == 1){
                        loadView.fail();
                    }

                }
            } else {
                if (page == 1){
                    loadView.fail();
                }
            }
        } else if (responseInfo.url.equals(Contant.LOAN_SEARCH)) {
            if (responseInfo.isRequestOk) {
                try {
                    searchBean = JSON.parseObject(responseInfo.content, CreditSearchBean.class);
                    if (searchBean != null && searchBean.getLoan_loan_item_list() != null) {
                        for (int i = 0; i < searchBean.getLoan_loan_item_list().size(); i++) {
                            if (searchBean.getLoan_loan_item_list().get(i).getSearch_type().equals("1")) {
                                mPledgeList = new ArrayList<>();
                                if (searchBean.getLoan_loan_item_list().get(i).getSearch_item() != null &&
                                        searchBean.getLoan_loan_item_list().get(i).getSearch_item().size() > 0)
                                    mPledgeList.addAll(searchBean.getLoan_loan_item_list().get(i).getSearch_item().get(0).getValue());
                                SearchValueBean value = new SearchValueBean();
                                value.setCheck(true);
                                value.setTitle("不限抵押");
                                value.setItem("-1");
                                mPledgeList.add(0, value);

                            } else if (searchBean.getLoan_loan_item_list().get(i).getSearch_type().equals("2")) {
                                mOrderList = new ArrayList<>();
                                if (searchBean.getLoan_loan_item_list().get(i).getSearch_item() != null &&
                                        searchBean.getLoan_loan_item_list().get(i).getSearch_item().size() > 0)
                                    mOrderList.addAll(searchBean.getLoan_loan_item_list().get(i).getSearch_item().get(0).getValue());
                                SearchValueBean value = new SearchValueBean();
                                value.setCheck(true);
                                value.setTitle("默认排序");
                                value.setItem("-1");
                                mOrderList.add(0, value);
                            } else if (searchBean.getLoan_loan_item_list().get(i).getSearch_type().equals("3")) {
                                mMoreList = new ArrayList<>();
                                if (searchBean.getLoan_loan_item_list().get(i).getSearch_item() != null &&
                                        searchBean.getLoan_loan_item_list().get(i).getSearch_item().size() > 0)
                                    mMoreList.addAll(searchBean.getLoan_loan_item_list().get(i).getSearch_item());
                            }
                        }

                        if (responseInfo.params.get("need_show").equals("2")) {
                            if (responseInfo.params.get("type").equals("1")) {
                                initPledgeDialog();
                                pledgeSearchDialog.show();
                            } else if (responseInfo.params.get("type").equals("2")) {
                                initOrderDialog();
                                orderSearchDialog.show();
                            } else if (responseInfo.params.get("type").equals("3")) {
                                initMoreDialog();
                                moreSearchDialog.show();
                            }

                        }
                    }
                } catch (Exception e) {

                }

            }
        }
    }





    public void scroll2Top(){
        if (mListView!=null&& loanList !=null){
            mListView.setSelection(0);
        }

    }
}
